<?php

/**
 * This is the model class for table "gnuhealth_hospital_ward".
 *
 * The followings are the available columns in table 'gnuhealth_hospital_ward':
 * @property integer $id
 * @property string $create_date
 * @property string $write_date
 * @property integer $create_uid
 * @property integer $write_uid
 * @property boolean $ac
 * @property boolean $telephone
 * @property boolean $private
 * @property boolean $guest_sofa
 * @property boolean $bio_hazard
 * @property integer $unit
 * @property string $extra_info
 * @property integer $floor
 * @property boolean $tv
 * @property boolean $microwave
 * @property string $state
 * @property integer $number_of_beds
 * @property boolean $internet
 * @property boolean $private_bathroom
 * @property integer $institution
 * @property boolean $refrigerator
 * @property integer $building
 * @property string $name
 * @property string $gender
 *
 * The followings are the available model relations:
 * @property ResUser $createU
 * @property PartyParty $institution0
 * @property ResUser $writeU
 */
class GnuhealthHospitalWard extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'gnuhealth_hospital_ward';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, gender', 'required'),
			array('create_uid, write_uid, unit, floor, number_of_beds, institution, building', 'numerical', 'integerOnly'=>true),
			array('create_date, write_date', 'length', 'max'=>6),
			array('ac, telephone, private, guest_sofa, bio_hazard, extra_info, tv, microwave, state, internet, private_bathroom, refrigerator', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, create_date, write_date, create_uid, write_uid, ac, telephone, private, guest_sofa, bio_hazard, unit, extra_info, floor, tv, microwave, state, number_of_beds, internet, private_bathroom, institution, refrigerator, building, name, gender', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'createU' => array(self::BELONGS_TO, 'ResUser', 'create_uid'),
			'institution0' => array(self::BELONGS_TO, 'PartyParty', 'institution'),
			'writeU' => array(self::BELONGS_TO, 'ResUser', 'write_uid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'create_date' => 'Create Date',
			'write_date' => 'Write Date',
			'create_uid' => 'Create Uid',
			'write_uid' => 'Write Uid',
			'ac' => 'Ac',
			'telephone' => 'Telephone',
			'private' => 'Private',
			'guest_sofa' => 'Guest Sofa',
			'bio_hazard' => 'Bio Hazard',
			'unit' => 'Unit',
			'extra_info' => 'Extra Info',
			'floor' => 'Floor',
			'tv' => 'Tv',
			'microwave' => 'Microwave',
			'state' => 'State',
			'number_of_beds' => 'Number Of Beds',
			'internet' => 'Internet',
			'private_bathroom' => 'Private Bathroom',
			'institution' => 'Institution',
			'refrigerator' => 'Refrigerator',
			'building' => 'Building',
			'name' => 'Name',
			'gender' => 'Gender',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('create_date',$this->create_date,true);
		$criteria->compare('write_date',$this->write_date,true);
		$criteria->compare('create_uid',$this->create_uid);
		$criteria->compare('write_uid',$this->write_uid);
		$criteria->compare('ac',$this->ac);
		$criteria->compare('telephone',$this->telephone);
		$criteria->compare('private',$this->private);
		$criteria->compare('guest_sofa',$this->guest_sofa);
		$criteria->compare('bio_hazard',$this->bio_hazard);
		$criteria->compare('unit',$this->unit);
		$criteria->compare('extra_info',$this->extra_info,true);
		$criteria->compare('floor',$this->floor);
		$criteria->compare('tv',$this->tv);
		$criteria->compare('microwave',$this->microwave);
		$criteria->compare('state',$this->state,true);
		$criteria->compare('number_of_beds',$this->number_of_beds);
		$criteria->compare('internet',$this->internet);
		$criteria->compare('private_bathroom',$this->private_bathroom);
		$criteria->compare('institution',$this->institution);
		$criteria->compare('refrigerator',$this->refrigerator);
		$criteria->compare('building',$this->building);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('gender',$this->gender,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return GnuhealthHospitalWard the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
